package com.innovations.inn.service.impl;

import com.innovations.common.utils.DateUtils;
import com.innovations.common.utils.uuid.IdGeneratorSnowflake;
import com.innovations.inn.domain.ResearchOutcomesFiles;
import com.innovations.inn.mapper.ResearchOutcomesFilesMapper;
import com.innovations.inn.service.IResearchOutcomesFilesService;
import java.util.List;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

/**
 * 科研成果附件Service业务层处理
 *
 * @author dp
 * @date 2024-08-09
 */
@Service
public class ResearchOutcomesFilesServiceImpl implements IResearchOutcomesFilesService {
    @Autowired
    private ResearchOutcomesFilesMapper researchOutcomesFilesMapper;
    @Autowired
    IdGeneratorSnowflake idGeneratorSnowflake;

    /**
     * 查询科研成果附件
     *
     * @param researchOutcomesFilesId 科研成果附件主键
     * @return 科研成果附件
     */
    @Override
    public ResearchOutcomesFiles selectResearchOutcomesFilesByResearchOutcomesFilesId(Long researchOutcomesFilesId) {
        return researchOutcomesFilesMapper.selectResearchOutcomesFilesByResearchOutcomesFilesId(researchOutcomesFilesId);
    }

    /**
     * 查询科研成果附件列表
     *
     * @param researchOutcomesFiles 科研成果附件
     * @return 科研成果附件
     */
    @Override
    public List<ResearchOutcomesFiles> selectResearchOutcomesFilesList(ResearchOutcomesFiles researchOutcomesFiles) {
        return researchOutcomesFilesMapper.selectResearchOutcomesFilesList(researchOutcomesFiles);
    }

    /**
     * 新增科研成果附件
     *
     * @param researchOutcomesFiles 科研成果附件
     * @return 结果
     */
    @Override
    public int insertResearchOutcomesFiles(ResearchOutcomesFiles researchOutcomesFiles) {
        researchOutcomesFiles.setCreateTime(DateUtils.getNowDate());
        return researchOutcomesFilesMapper.insertResearchOutcomesFiles(researchOutcomesFiles);
    }

    /**
     * 修改科研成果附件
     *
     * @param researchOutcomesFiles 科研成果附件
     * @return 结果
     */
    @Override
    public int updateResearchOutcomesFiles(ResearchOutcomesFiles researchOutcomesFiles) {
        return researchOutcomesFilesMapper.updateResearchOutcomesFiles(researchOutcomesFiles);
    }

    /**
     * 批量删除科研成果附件
     *
     * @param researchOutcomesFilesIds 需要删除的科研成果附件主键
     * @return 结果
     */
    @Override
    public int deleteResearchOutcomesFilesByResearchOutcomesFilesIds(Long[] researchOutcomesFilesIds) {
        return researchOutcomesFilesMapper.deleteResearchOutcomesFilesByResearchOutcomesFilesIds(researchOutcomesFilesIds);
    }

    /**
     * 删除科研成果附件信息
     *
     * @param researchOutcomesFilesId 科研成果附件主键
     * @return 结果
     */
    @Override
    public int deleteResearchOutcomesFilesByResearchOutcomesFilesId(Long researchOutcomesFilesId) {
        return researchOutcomesFilesMapper.deleteResearchOutcomesFilesByResearchOutcomesFilesId(researchOutcomesFilesId);
    }

    /**
     * 实体数据补全
     *
     * @param researchOutcomesFiles 实体
     * @param userId                用户id
     * @param crateType             创建类型 1：新增 2：修改
     */
    @Override
    public void completeData(ResearchOutcomesFiles researchOutcomesFiles, Long userId, Integer crateType) {
        //主键
        if (researchOutcomesFiles.getResearchOutcomesFilesId() == null || "".equals(researchOutcomesFiles.getResearchOutcomesFilesId())) {
            researchOutcomesFiles.setResearchOutcomesFilesId(idGeneratorSnowflake.nextId());
        }
        //创建人、创建时间
        if (crateType == 1) {
            if (researchOutcomesFiles.getCreateBy() == null || "".equals(researchOutcomesFiles.getCreateBy())) {
                researchOutcomesFiles.setCreateBy(userId);
            }
            if (researchOutcomesFiles.getCreateTime() == null) {
                researchOutcomesFiles.setCreateTime(DateUtils.getNowDate());
            }
        }
//        //修改人
//        if (researchOutcomesFiles.getModifyBy() == null) {
//            researchOutcomesFiles.setModifyBy(userId);
//        }
//        //修改时间
//        if (researchOutcomesFiles.getModifyTime() == null) {
//            researchOutcomesFiles.setModifyTime(DateUtils.getNowDate());
//        }
    }
}
